import requests

# cookie登录
# 发送验证码请求,获取验证码cookie信息(对于像验证码这类非静态的、需要请求的元素，请求时要获取并加上cookie信息)
url_verify = "http://localhost/index.php?m=Home&c=User&a=verify"
r_verify = requests.get(url_verify)
print(r_verify.cookies)
# 发送登录请求
url_login = "http://localhost/index.php?m=Home&c=User&a=do_login"
head = {"Content-Type": "application/x-www-form-urlencoded"}
data = {
    "username": "13800138006",
    "password": "123456",
    "verify_code": "8888"
}

request_login = requests.post(url_login, json=data, headers=head, cookies=r_verify.cookies)
print(request_login.json())
# 查看订单信息(复制超链接地址)
# url_indent = "http://localhost/index.php/Home/Order/order_list.html"
# r_indent = requests.get(url_indent, cookies=r_verify.cookies)
# print(r_indent.text)
# 查看账户余额
# url_accountmoney = "http://localhost/index.php/Home/User/recharge.html"
# r_accountmoney = requests.get(url_accountmoney, cookies=r_verify.cookies)
# print(r_accountmoney.text)
# session登陆Tpshop
# 创建session实例
session = requests.session()
url_verify = "http://localhost/index.php?m=Home&c=User&a=verify"
session.get(url_verify)
# 发送登录请求
url_login = "http://localhost/index.php?m=Home&c=User&a=do_login"
head = {"Content-Type": "application/x-www-form-urlencoded"}
data = {
    "username": "13800138006",
    "password": "123456",
    "verify_code": "8888"
}
r = session.post(url_login, data=data, headers=head)
url_accountmoney1 = "http://localhost/index.php/Home/User/recharge.html"
r_accountmoney1 = requests.get(url_accountmoney1)
print(r_accountmoney1.text)
